package dao;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.*;
import engine.BIEngine0_1.AlgorithmOperator;
import net.HttpRequest;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import controller.RegisterAlgorithm;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import utils.Log4jInit;
import utils.StaticUtil;
import utils.UserLogUtil;

public class FileUploadDAO {
    private HttpServletRequest request;
    private long maxSize = -1;
    private boolean isSuccess = true;
    private String SAVE_PATH;
    private AlgorithmDao algorithmDao = new AlgorithmDao();

    public FileUploadDAO(HttpServletRequest request, HttpServletResponse response, long maxSize, String SAVE_PATH) {
        this.request = request;
        this.maxSize = maxSize;
        this.SAVE_PATH = SAVE_PATH.replace("\\", "/");

    }

    /**
     * 执行算法上传  By朱耀堃
     * @param userId
     * @return
     * @throws UnsupportedEncodingException
     * @throws FileUploadException
     */
    public boolean executeUpload(String userId) throws UnsupportedEncodingException, FileUploadException {
        AlgorithmDetail algorithm = new AlgorithmDetail();
        List<AlgorithmInput> inputsList = new ArrayList<>();
        List<AlgorithmOutput> outputsList = new ArrayList<>();
        List<AlgorithmParam> paramsList = new ArrayList<>();
        String algorithmId = null;
        boolean coverFlag = false;
        boolean isUpdate = true;
        File file = new File(SAVE_PATH);
        // 判断文件保存目录是否存在
        if (!file.exists() && !file.isDirectory()) {
            file.mkdir();
        }
        // 使用Apache组件上传文件的步骤：
        // 1.创建一个DiskFileItemFactory
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // 2.创建一个文件上传解析器
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setFileSizeMax(maxSize);
        // 解决中文乱码
        upload.setHeaderEncoding("UTF-8");
        // 3.判断提交的数据是否合法
        if (!ServletFileUpload.isMultipartContent(request)) {
            // 按照传统方法获取
        	RegisterAlgorithm.result = "出错了，请联系管理员";
            return false;
        }
        // 4.使用解析器上传数据，解析返回的是List<FileItem>,FileItem对应一个form表单
        List<FileItem> list = upload.parseRequest(request);
        /**
         * 解析上传的域
         */
        for (FileItem item : list) {
            /**
             * form表单域
             */
            if (item.isFormField()) {
                if ("algorithmId".equals(item.getFieldName())) {
                    algorithmId = item.getString("UTF-8");
                }
                if ("algorithm".equals(item.getFieldName())) {
                    JSONObject algorithmDetail = JSONObject.fromObject(item.getString("UTF-8"));
                    JSONArray inputs = algorithmDetail.getJSONArray("inputCount");
                    for (int i = 0; i < inputs.size(); i++) {
                        JSONObject oneInput = inputs.getJSONObject(i);
                        inputsList.add(new AlgorithmInput(oneInput.getString("inputName").equals("") ? "-i" + i : oneInput.getString("inputName"),
                                oneInput.getString("type"), oneInput.getString("inputIntroduction")
                                , oneInput.getString("inputName").equals(""), oneInput.getString("suffix")));
                    }
                    JSONArray outputs = algorithmDetail.getJSONArray("outputCount");
                    for (int i = 0; i < outputs.size(); i++) {
                        JSONObject oneOutput = outputs.getJSONObject(i);
                        outputsList.add(new AlgorithmOutput(oneOutput.getString("outputName").equals("") ? "-o" + i : oneOutput.getString("outputName"),
                                oneOutput.getString("type"), oneOutput.getString("outputIntroduction")
                                , oneOutput.getString("outputName").equals(""), oneOutput.getString("suffix")));
                    }
                    JSONArray params = algorithmDetail.getJSONArray("paramsCount");
                    for (int i = 0; i < params.size(); i++) {
                        JSONObject oneParam = params.getJSONObject(i);
                        AlgorithmParam param = new AlgorithmParam(oneParam.getString("paramSymbol").equals("") ? "-p" + i : oneParam.getString("paramSymbol"),
                                oneParam.getString("paramType"), oneParam.getString("paramIntroduction")
                                , oneParam.getString("paramSymbol").equals(""));
                        param.setParamDefaultValue(oneParam.getString("paramDefaultValue"));
                        paramsList.add(param);
                    }
                    try {
                        algorithmId = algorithmDetail.getString("id");
                    } catch (JSONException e) {
                        algorithmId = null;
                    }
                    try {
                        algorithm.setCompanyName(algorithmDetail.getString("companyName"));
                        algorithm.setContainGpu(Boolean.parseBoolean(algorithmDetail.getString("isContainGpu")));
                        algorithm.setDelete(false);
                        algorithm.setFunctionId(algorithmDetail.getString("algorithmFunction"));
                        algorithm.setIntroduction(algorithmDetail.getString("introduction"));
                        algorithm.setName(algorithmDetail.getString("name"));
                        algorithm.setInputCount(inputsList.size());
                        algorithm.setOutputCount(outputsList.size());
                        algorithm.setParamsCount(paramsList.size());
                        algorithm.setVersion(algorithmDetail.getString("version"));
                        algorithm.setTypeId(algorithmDetail.getString("algorithmType"));
                        algorithm.setPlatform(algorithmDetail.getString("platform"));
                        algorithm.setGenetic(Boolean.parseBoolean(algorithmDetail.getString("genetic")));
                        algorithm.setUseMpi(Boolean.parseBoolean(algorithmDetail.getString("isUseMpi")));
                        algorithm.setCpuNum(algorithmDetail.getString("cpuNum"));
                        algorithm.setMinCpuIdle(Float.parseFloat(HttpConfig.cpuRemaining));
                        algorithm.setMinRamRemaining(Float.parseFloat(HttpConfig.memoryRemaining));
                        algorithm.setPostfix(algorithmDetail.getString("postfix"));
                        algorithm.setUserId(userId);
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                        RegisterAlgorithm.result = "表单数据出错";
                        return false;
                    } catch (JSONException e) {
                        e.printStackTrace();
                        RegisterAlgorithm.result = "表单数据出错";
                        return false;
                    }
                }
                /**
                 * 是否为版本覆盖，表单域有一个键名为coverFlag的值，“true”或“false”
                 */
                if ("coverFlag".equals(item.getFieldName())) {
                    coverFlag = Boolean.parseBoolean(item.getString("UTF-8"));
                }
            } else
            /**
             * 文件域
             */
            {
                AlgorithmDetail algorithmDetail = algorithmId==null?null:algorithmDao.getAlgorithmDetailWithoutUserId(algorithmId);
                //这里判断是否进行版本覆盖，主要有两点：1、algorithm对象里面的version；2、存储文件的名称
                if(coverFlag&&algorithmId!=null){
                    algorithm.setVersion(algorithmDetail.getVersion());
                }
                isUpdate = false;
                String newAlgorithmId = algorithmDao.getNextAlgorithmId() + "";
                String fileName = item.getName() + "";
                // 如果封装的上传文件
                String fileType = item.getName();
                if (fileType == null || "".equals(fileType.trim())) {
                    continue;
                }
                // 不同浏览器提交的文件名是不一样的，有的是带路径的
                // 处理文件路径部分，只保留文件名
                fileType = fileType.substring(fileType.lastIndexOf("/") + 1);
                fileType = fileType.substring(fileType.lastIndexOf("\\") + 1);
                fileType = fileType.substring(fileType.lastIndexOf("."), fileType.length());
                String path = null;
                if(algorithmId==null){
                    path = SAVE_PATH + newAlgorithmId + "/";
                }else{
                    path = algorithmDetail.getLocationUri().substring(0,algorithmDetail.getLocationUri().lastIndexOf("/")+1);
                }
                File directoryFile = new File(path);
                long fileSize = item.getSize();
                if (fileName.equals("") && fileSize == 0) {
                    this.isSuccess = false;
                    RegisterAlgorithm.result = "算法文件为空";
                } else {
                    try {
                        if (!directoryFile.exists()) {
                            directoryFile.mkdirs();
                            if(HttpConfig.serverPlatform.equals("linux")){
                            	AlgorithmOperator.chmod(path);
                            }
                        }
                        String filePath = path + fileName;
                        String copyFilePath = path + algorithm.getVersion() + "/";
                        File uploadFile = new File(filePath);
                        item.write(uploadFile);
                        if(HttpConfig.serverPlatform.equals("linux")){
                        	AlgorithmOperator.chmod(uploadFile.getPath());
                        }
                        
                        this.isSuccess = true;
                        //将保存的位置添加到数据库里面
                        algorithm.setLocationUri(filePath);
                        StaticUtil.cpFile(filePath, copyFilePath);
                    } catch (Exception e) {
                        this.isSuccess = false;
                        RegisterAlgorithm.result = "出错了，请联系管理员";
                        e.printStackTrace();
                    }
                    // 删除临时文件
                    item.delete();
                }
            }
        }
        String autoAlgorithmId = "";
        if(algorithmId==null){
        	if(isUpdate){
        		RegisterAlgorithm.result = "新增算法时未上传算法文件";
        		isSuccess = false;
        	}else{
        	    HttpResult result = algorithmDao.insertAlgorithmDetail(algorithm,inputsList,outputsList,paramsList);
        		isSuccess = isSuccess && result.isResult();
        		if(isSuccess){
        			RegisterAlgorithm.result = "添加算法成功";
        			autoAlgorithmId = result.getMessage();
        			//记录操作行为
                    UserLogUtil.dbLog(LogEnum.algorithm,
                            LogEnum.add,
                            userId,
                            LogEnum.algorithm.getValue()+"名称："+algorithm.getName());
        		}else{
        			RegisterAlgorithm.result = "出错了，请联系管理员";
        			algorithmDao.deleteAlgorithmById(result.getMessage());
        			isSuccess = false;
        		}
        	}
            /**
             * 新增算法均需要自动生成一个单算法模型
             */
        	if(isSuccess){
        	    JSONObject json = JSONObject.fromObject(SingleAlgorithmModelJson.getInstance());
        	    JSONArray blocksArray = json.getJSONArray("blocks");
        	    for(int i=0;i<blocksArray.size();i++){
        	        JSONObject oneBlock = blocksArray.getJSONObject(i);
        	        if(oneBlock.containsKey("dataId")){
                        oneBlock.put("dataId",autoAlgorithmId);
                        oneBlock.put("blockName",algorithm.getName());
                        oneBlock.put("blockTitle",algorithm.getName()+"——自动模型");
                        JSONArray paramConfigDefault = oneBlock.getJSONArray("paramsConfigDefault");
                        for(int j=0;j<paramsList.size();j++){
                            JSONObject tempJsonObject = new JSONObject();
                            tempJsonObject.put("paramName",paramsList.get(j).getParamSymbol());
                            tempJsonObject.put("type",paramsList.get(j).getParamType());
                            tempJsonObject.put("desc",paramsList.get(j).getParamIntroduction());
                            //这里默认单算法模型的参数值为空
                            tempJsonObject.put("paramValue",paramsList.get(j).getParamDefaultValue());
                            paramConfigDefault.add(tempJsonObject);
                        }
                    }
                }
        	    isSuccess = isSuccess&&new ModelDao().addModelAndAlgorithmId(autoAlgorithmId,algorithm.getName(),algorithm.getUserId(),"",0
                        ,"",json.toString(),0,algorithm.getIntroduction(),1).size()>0;
                //记录操作行为
        	    UserLogUtil.dbLog(LogEnum.model,
                        LogEnum.add,
                        userId,
                        LogEnum.addModelByAlgorithm.getValue());
            }
        }else{
            AlgorithmDetail algorithmDetail = algorithmId==null?null:algorithmDao.getAlgorithmDetailWithoutUserId(algorithmId);
            if(algorithm.getLocationUri()==null)algorithm.setLocationUri(algorithmDetail.getLocationUri());
            boolean two = algorithmDao.updataAlgorithmById(userId,algorithmId,algorithm,inputsList,outputsList,paramsList);
            isSuccess = isSuccess && two;
            if(isSuccess){
        		RegisterAlgorithm.result = "修改算法成功";
        		ModelDao modelDao = new ModelDao();
        		int modelId = modelDao.getModelIdByAlgorithmId(algorithmId);
                JSONObject json = JSONObject.fromObject(SingleAlgorithmModelJson.getInstance());
                JSONArray blocksArray = json.getJSONArray("blocks");
                for(int i=0;i<blocksArray.size();i++){
                    JSONObject oneBlock = blocksArray.getJSONObject(i);
                    if(oneBlock.containsKey("dataId")){
                        oneBlock.put("dataId",algorithmId);
                        oneBlock.put("blockName",algorithm.getName());
                        oneBlock.put("blockTitle",algorithm.getName()+"——自动模型");
                        JSONArray paramConfigDefault = oneBlock.getJSONArray("paramsConfigDefault");
                        for(int j=0;j<paramsList.size();j++){
                            JSONObject tempJsonObject = new JSONObject();
                            tempJsonObject.put("paramName",paramsList.get(j).getParamSymbol());
                            tempJsonObject.put("type",paramsList.get(j).getParamType());
                            tempJsonObject.put("desc",paramsList.get(j).getParamIntroduction());
                            //这里默认单算法模型的参数值为空
                            tempJsonObject.put("paramValue",paramsList.get(j).getParamDefaultValue());
                            paramConfigDefault.add(tempJsonObject);
                        }
                    }
                }
                isSuccess = isSuccess&&modelDao.updateModelJsonAndIntroduction(json.toString(),algorithm.getIntroduction(),modelId);
                //记录操作行为
                UserLogUtil.dbLog(LogEnum.model,
                        LogEnum.update,
                        userId,
                        LogEnum.model.getValue()+"编号："+modelId);
        		UserLogUtil.dbLog(LogEnum.algorithm,
                        LogEnum.update,
                        userId,
                        LogEnum.algorithm.getValue()+"编号："+algorithmId);
    		}
    		else{
    			RegisterAlgorithm.result = "出错了，请联系管理员";
    			isSuccess = false;
    		}
        }
        return isSuccess;
    }

    public static void main(String[] args) {
        String aa = "{\n" +
                "    \"fatherTaskId\":\"11\",\n" +
                "    \"modelId\": \"207\",\n" +
                "    \"taskNumber\": \"4\",\n" +
                "    \"params\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"-p0\",\n" +
                "                        \"paramValue\": \"11\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"-p0\",\n" +
                "                        \"paramValue\": \"22\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"inputs\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"01:new_test2\",\n" +
                "                \"inputName\": \"-i0\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"a/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"01:new_test2\",\n" +
                "                \"inputName\": \"-i0\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"bbbbb/a_b/a_b_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"outputs\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"05:generic1\",\n" +
                "                \"outputName\": \"-o0\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"11.2\"\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"blockName\": \"05:generic1\",\n" +
                "                \"outputName\": \"-o0\",\n" +
                "                \"outputAddress\": \"\",\n" +
                "                \"outputValue\": \"11.2\"\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"other说明\":\"优先级和并行策略\",\n" +
                "    \"other\": [\n" +
                "        {\n" +
                "            \"Priority\": \"50\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"Priority\": \"80\"\n" +
                "        }\n" +
                "    ]" +
                "}";
        String ndw = "{\n" +
                "    \"fatherTaskId\": \"121\",\n" +
                "    \"modelId\": \"250\",\n" +
                "    \"taskNumber\": \"2\",\n" +
                "    \"params\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"p1\",\n" +
                "                        \"paramValue\": \"1_1_1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"p2\",\n" +
                "                        \"paramValue\": \"1_1_2\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"p1\",\n" +
                "                        \"paramValue\": \"1_2_1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"p2\",\n" +
                "                        \"paramValue\": \"1_2_2\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_3\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"-p0\",\n" +
                "                        \"paramValue\": \"1_2_1\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_1\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"p1\",\n" +
                "                        \"paramValue\": \"1_1_1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"p2\",\n" +
                "                        \"paramValue\": \"1_1_2\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"p1\",\n" +
                "                        \"paramValue\": \"1_2_1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"paramName\": \"p2\",\n" +
                "                        \"paramValue\": \"1_2_2\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_3\",\n" +
                "                \"param\": [\n" +
                "                    {\n" +
                "                        \"paramName\": \"-p0\",\n" +
                "                        \"paramValue\": \"1_2_1\"\n" +
                "                    }\n" +
                "                ]\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"inputs\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_3\",\n" +
                "                \"blockName\": \"03:zipzip\",\n" +
                "                \"inputName\": \"-i0\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"b/b_a/b_a_b.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_3\",\n" +
                "                \"blockName\": \"03:zipzip\",\n" +
                "                \"inputName\": \"-i0\",\n" +
                "                \"frontOutput\": {\n" +
                "                    \"frontOutputName\": \"b/b_a/b_a_a.jpg\",\n" +
                "                    \"blockId\": \"uiStart_1\",\n" +
                "                    \"dataId\": \"\"\n" +
                "                }\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"outputs\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"blockName\": \"02:test5\",\n" +
                "                \"outputName\": \"o1\",\n" +
                "                \"outputAddress\": \"b/\",\n" +
                "                \"outputValue\": \".1\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"blockName\": \"02:test5\",\n" +
                "                \"outputName\": \"o2\",\n" +
                "                \"outputAddress\": \"b/\",\n" +
                "                \"outputValue\": \".2\"\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"blockName\": \"02:test5\",\n" +
                "                \"outputName\": \"o1\",\n" +
                "                \"outputAddress\": \"b/\",\n" +
                "                \"outputValue\": \".1\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"blockId\": \"uiAlgorithm_2\",\n" +
                "                \"blockName\": \"02:test5\",\n" +
                "                \"outputName\": \"o2\",\n" +
                "                \"outputAddress\": \"b/\",\n" +
                "                \"outputValue\": \".2\"\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"data\": [\n" +
                "        [\n" +
                "            {\n" +
                "                \"dataBlockName\": \"外部数据源1\",\n" +
                "                \"dataName\": \"+uiData_1+1\",\n" +
                "                \"dataValue\": \"b/b_a/b_a_a.jpg\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"dataBlockName\": \"外部数据源2\",\n" +
                "                \"dataName\": \"+uiData_2+1\",\n" +
                "                \"dataValue\": \"b/b_a/b_a_b.jpg\"\n" +
                "            }\n" +
                "        ],\n" +
                "        [\n" +
                "            {\n" +
                "                \"dataBlockName\": \"外部数据源1\",\n" +
                "                \"dataName\": \"+uiData_1+1\",\n" +
                "                \"dataValue\": \"b/b_a/b_a_b.jpg\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"dataBlockName\": \"外部数据源2\",\n" +
                "                \"dataName\": \"+uiData_2+1\",\n" +
                "                \"dataValue\": \"b/b_a/b_a_a.jpg\"\n" +
                "            }\n" +
                "        ]\n" +
                "    ],\n" +
                "    \"other说明\": \"优先级和并行策略\",\n" +
                "    \"other\": [\n" +
                "        {\n" +
                "            \"Priority\": \"50\",\n" +
                "            \"ParallelStrategy\": \"-ut\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";
        ndw = ndw.replaceAll("\\+","%2B");
        JSONObject aaa = JSONObject.fromObject(ndw);
        String result = HttpRequest.sendPost("http://localhost:8080/JCPT/ws/task/start","data="+ndw);
        Log4jInit.logger.info(result);
    }
}